package com.company.bs2023;

/**
 * TODO
 *
 * @author jianf
 * @date 2023年04月16 10:41
 */
public class RotateBalls {

    public static void main(String[] args) {
        RotateBalls solution = new RotateBalls();
//        char[] balls = {'a', 'd', 's', 'd', 'f', 'g'};
//        char[] result = solution.rotate(6, balls, 3);
       /* //1
        char[] balls = {'a', 'b', 'c', 'd', 'e','f', 'g'};
        char[] result = solution.rotate(7, balls, 3);*/
        //2 abcdesadfg397hfg
        char[] balls = {'a', 'b', 'c', 'd', 'e','s', 'a','d', 'f','g', '3','9', '7','h','f', 'g'};
        char[] result = solution.rotate(16, balls, 37);
        /*//3
        char[] balls = {'a', 'd', 's', 'd', 'f', 'g'};
        char[] result = solution.rotate(6, balls, 3);
        //4
        char[] balls = {'a', 'd', 's', 'd', 'f', 'g'};
        char[] result = solution.rotate(6, balls, 3);
        //5
        char[] balls = {'a', 'd', 's', 'd', 'f', 'g'};
        char[] result = solution.rotate(6, balls, 3);*/
        System.out.println(result);
    }

    public char[] rotate(int m, char[] balls, int n) {
        int x = n % m;
        char[] ret = new char[m];
        int s = 0;
        for (int i = m - x; i < m; i++) {
            ret[s++] = balls[i];
        }
        for (int i = 0; i < (m - x); i++) {
            ret[x + i] = balls[i];
        }
        return ret;
    }
}
